package com.coollang.smartbra.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.coollang.smartbra.R;
import com.coollang.smartbra.utils.DisplayUtils;
import com.coollang.smartbra.utils.UIUtils;

import java.util.List;

import static com.coollang.smartbra.utils.UIUtils.getResources;

/**
 * GirdView 数据适配器
 */
public class GridViewAdapter extends BaseAdapter {
    private final int width;
    Context context;
    List<String> list;
    private int currentPosition = -1;

    public GridViewAdapter(Context _context, List<String> _list, int width) {
        this.list = _list;
        this.width = width;
        this.context = _context;
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        convertView = UIUtils.inflate(R.layout.item_gridview);
        TextView tv = (TextView) convertView.findViewById(R.id.tv);
        tv.setText(list.get(position));
        LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(DisplayUtils.dip2px(context, 200), DisplayUtils.dip2px(context, 50));
        tv.setLayoutParams(params);
        if (currentPosition == position) {
            tv.setTextColor(getResources().getColor(R.color.progrss_bg));
            tv.setTextSize(16);
        } else {
            tv.setTextColor(getResources().getColor(R.color.black_80));
            tv.setTextSize(14);
        }
        return convertView;
    }

    public void notif(int position) {
        this.currentPosition = position;
        notifyDataSetChanged();
    }


}